package com.itheima;

/**
 * 2025/4/18 20:07
 */
public class Card {
    //车牌号码
    private String carNumber;
    //车主姓名
    private String name;
    //电话号码
    private String phone;
    //卡片余额
    private double balance;

    public Card() {
    }

    public Card(String carNumber, String name, String phone, double balance) {
        this.carNumber = carNumber;
        this.name = name;
        this.phone = phone;
        this.balance = balance;
    }

    public String getCarNumber() {
        return carNumber;
    }

    public void setCarNumber(String carNumber) {
        this.carNumber = carNumber;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    /**
     *支付的方法
     * @param money 支付的金额
     * @return true表示支付成功，false表示支付失败
     */
    public boolean pay(double money){
        //判断余额是否充足
        if(balance >= money){
            System.out.println(this +"支付成功");
            //余额充足，支付成功
            balance -= money;
            return true;
        }else{
            System.out.println(this +"支付失败");
            //余额不足，支付失败
            return false;
        }

    }

    /**
     * 充值的方法
     */
    public void charge(double money){
        if (money <=0){
            System.out.println("充值失败，充值金额必须大于0");
            return;
        }
        balance += money;
        System.out.println(this + "充值成功");
    }

    @Override
    public String toString() {
        return "Card{" +
                "carNumber='" + carNumber + '\'' +
                ", name='" + name + '\'' +
                ", phone='" + phone + '\'' +
                ", balance=" + balance +
                '}';
    }
}
